package com.ywjg.serviceimp;

import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;

import javax.annotation.Resource;

import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Pageable;
import org.springframework.data.domain.Sort;
import org.springframework.data.domain.Sort.Direction;
import org.springframework.stereotype.Service;

import com.ywjg.dao.HotGoodDao;
import com.ywjg.model.HotGood;
import com.ywjg.service.IHotGoodService;

@Service
public class HotGoodService implements IHotGoodService {
	@Resource
	HotGoodDao hotGoodDao;

	/* (non-Javadoc)
	 * @see com.ywjg.serviceimp.IHotGoodService#findAll()
	 */
	public List<HotGood> findAll() {
		List<HotGood> goods = new ArrayList<HotGood>();
		Pageable pageable = new PageRequest(0, 4, new Sort(Direction.DESC, "timestamp"));
		Iterable<HotGood> iGoods = hotGoodDao.findAll(pageable);
		
		Iterator<HotGood> iterator = iGoods.iterator();
		while (iterator.hasNext()) {
			HotGood hotGood = (HotGood) iterator.next();
			goods.add(hotGood);
		}
		return goods;
	}

}
